package com.lycafly;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.lycafly.fragment.view.ExpanAnimation;
import com.lycafly.fragment.view.OnSwipeTouchListener;

@EActivity
public class HotelSerchActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_hotel);
		// Show the Up button in the action bar.
		setupActionBar();
	}

	/**
	 * Set up the {@link android.app.ActionBar}.
	 */
	private void setupActionBar() {

		getActionBar().setDisplayHomeAsUpEnabled(true);

	}

	@ViewById(R.id.expandImageView)
	ImageView expandableView;

	@ViewById(R.id.expndableView)
	LinearLayout expndableView;

	int height;

	@Click({ R.id.titlebar })
	void onClick(View view) {

		switch (view.getId()) {

		case R.id.titlebar:
			//System.out.println("onclick");
			// System.out.println(expndableView.getVisibility());

			if (expndableView.getVisibility() == View.VISIBLE) {
				//System.out.println("if ");
				ExpanAnimation a = new ExpanAnimation(expndableView, 300,
						ExpanAnimation.COLLAPSE);
				//height = a.getHeight();
				expndableView.startAnimation(a);
				expandableView.setImageResource(R.drawable.arrow_light);
			} else {
				//System.out.println("elese ");
				ExpanAnimation a = new ExpanAnimation(expndableView, 300,
						ExpanAnimation.EXPAND);
				//a.setHeight(height);
				expndableView.startAnimation(a);
				expandableView
						.setImageResource(R.drawable.arrow_light_inverted);
			}
			break;

		default:
			break;
		}
	}

	@AfterViews
	void iniUi() {
		expndableView.setOnTouchListener(new OnSwipeTouchListener() {
			public void onSwipeTop() {
				ExpanAnimation a = new ExpanAnimation(expndableView, 300,
						ExpanAnimation.COLLAPSE);
				height = a.getHeight();
				expndableView.startAnimation(a);
				expandableView.setImageResource(R.drawable.arrow_light);
			}

			public void onSwipeRight() {

			}

			public void onSwipeLeft() {

			}

			public void onSwipeBottom() {

			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		// getMenuInflater().inflate(R.menu.hotel_serch, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case android.R.id.home:
			// This ID represents the Home or Up button. In the case of this
			// activity, the Up button is shown. Use NavUtils to allow users
			// to navigate up one level in the application structure. For
			// more details, see the Navigation pattern on Android Design:
			//
			// http://developer.android.com/design/patterns/navigation.html#up-vs-back
			//
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

}
